<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let random =Math.floor(Math.random()*(10-1+1)+1)
        let count = 0
        while(true){
            count++
       // document.write(Math.floor(Math.random()*(10-1+1))+1)
        let guess = +prompt('请输入1-10之间的数字')
        if (guess >10 || guess < 1)
    {alert('请输入有效的数');
        continue;
    }
        if (guess > random){
            alert('猜大了')
        }else if(guess <random){
            alert('猜小了')
        }else{
            alert(`猜对了,共猜了${count}次`);
            break;
        }
    }
    </script>
</body>
</html>